package com.example.moshudriver.adapter;

import java.util.ArrayList;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.BeeFramework.Utils.TimeUtil;
import com.BeeFramework.Utils.Utils;
import com.BeeFramework.adapter.BeeBaseAdapter;
import com.sgr.dykdriver.R;
import com.example.moshudriver.protocol.COUPON_INFO;
import com.example.moshudriver.protocol.ORDER_INFO;
import com.example.moshudriver.utils.StringUtils;
import com.nostra13.universalimageloader.core.ImageLoader;

public class CouponListAdapter extends BeeBaseAdapter {
	protected ImageLoader mImageLoader = ImageLoader.getInstance();

	public CouponListAdapter(Context c, ArrayList orderList) {
		super(c, orderList);
	}

	public class E0_OrderCellHolder extends BeeCellHolder {
		private TextView coupon_price;
		private TextView coupon_content;
		TextView coupon_time;
		TextView coupon_staus;
		RelativeLayout cell_view;

	}

	@Override
	protected BeeCellHolder createCellHolder(View cellView) {
		E0_OrderCellHolder holder = new E0_OrderCellHolder();

		holder.cell_view = (RelativeLayout) cellView
				.findViewById(R.id.e0_cell_view);
		holder.coupon_price = (TextView) cellView
				.findViewById(R.id.coupon_price);
		holder.coupon_content = (TextView) cellView
				.findViewById(R.id.coupon_content);
		holder.coupon_time = (TextView) cellView.findViewById(R.id.coupon_time);
		holder.coupon_staus = (TextView) cellView
				.findViewById(R.id.coupon_staus);
		;
		return holder;
	}

	// 绑定订单数据
	@Override
	protected View bindData(int position, View cellView, ViewGroup parent,
			BeeCellHolder h) {
		COUPON_INFO coupon = (COUPON_INFO) dataList.get(position);
		E0_OrderCellHolder holder = (E0_OrderCellHolder) h;
		if (coupon != null) {
			if(coupon.coupon.type==0){
				holder.coupon_price.setText(coupon.coupon.money + "元");
			}else{
				holder.coupon_price.setText( coupon.mount+ "元");
			}
			holder.coupon_content.setText(coupon.coupon.content);
			// 只保留年月日
			holder.coupon_time.setText("有效期至"
					+ coupon.coupon.end_time.substring(0, 10));
			if (coupon.state == 0) {
				holder.coupon_staus.setText("未领取");
				holder.cell_view.setBackgroundResource(R.drawable.coupon_unuse);
			} else if (coupon.state == 1) {
				holder.cell_view.setBackgroundResource(R.drawable.coupon_unuse);
				holder.coupon_staus.setText("未使用");
			} else if (coupon.state == 2) {
				holder.coupon_staus.setText("已失效");
				holder.cell_view.setBackgroundResource(R.drawable.coupon_used);
			} else {
				holder.coupon_staus.setText("已使用");
				holder.cell_view.setBackgroundResource(R.drawable.coupon_used);
			}

		}

		return null;
	}

	@Override
	public View createCellView() {
		return mInflater.inflate(R.layout.coupon_cell, null);
	}
}
